from Scheduler import Scheduler
import queue
import OS

class RoundRobin(Scheduler):
    
    def __init__(self,aQuantum):
        self.readyQueue=queue.Queue()
        self.quantum = aQuantum
           
    def addPCB(self,aPCB): 
        self.readyQueue.put(aPCB)
      
    def getReadyQueue(self):
        return self.readyQueue
            
    def nextPCB(self):
        return self.readyQueue.get()
    
    def isQuantum(self):
        return True
    
    def getQuantum(self):
        return self.quantum
    
    def nextPCB2(self):
        instructionsToExecute = 0 
        quantumUsed = 0  
        pcb = self.readyQueue.get()
        programCounter = pcb.getPC() 
        while(pcb.isThereNextInst()):
            x = quantumUsed + pcb.getCurrentInstructionTime()
            if((self.getQuantum())>= x):
                instructionsToExecute= instructionsToExecute+ 1
                quantumUsed = quantumUsed + pcb.getCurrentInstructionTime()
            pcb.advance() 
        pcb.setInstToExecute(instructionsToExecute)
        pcb.setPC(programCounter) 
        return pcb 
                
            